#include "look1_iu16lftu8DfIf_binlcapw.h"
#include "rtwtypes.h"

real32_T look1_iu16lftu8DfIf_binlcapw(uint16_T u0, const uint16_T bp0[], const
  uint8_T table[], uint32_T maxIndex)
{
  real32_T frac;
  real32_T y;
  uint32_T iLeft;
  if (u0 <= bp0[0U]) {
    iLeft = 0U;
    frac = 0.0F;
  } else if (u0 < bp0[maxIndex]) {
    uint32_T bpIdx;
    uint32_T iRght;
    bpIdx = maxIndex >> 1U;
    iLeft = 0U;
    iRght = maxIndex;
    while (iRght - iLeft > 1U) {
      if (u0 < bp0[bpIdx]) {
        iRght = bpIdx;
      } else {
        iLeft = bpIdx;
      }

      bpIdx = (iRght + iLeft) >> 1U;
    }

    uint16_T bpLeftVar;
    bpLeftVar = bp0[iLeft];
    frac = (real32_T)(uint16_T)((uint32_T)u0 - bpLeftVar) / (real32_T)(uint16_T)
      ((uint32_T)bp0[iLeft + 1U] - bpLeftVar);
  } else {
    iLeft = maxIndex;
    frac = 0.0F;
  }

  if (iLeft == maxIndex) {
    y = table[iLeft];
  } else {
    uint8_T yL_0d0;
    yL_0d0 = table[iLeft];
    y = ((real32_T)table[iLeft + 1U] - (real32_T)yL_0d0) * frac + (real32_T)
      yL_0d0;
  }

  return y;
}
